<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<!--view层-->
<div id="app">
  <h1>{{message}}</h1>
  <h1>view层不要写太复杂的逻辑方案来处理,该方案不推荐使用</h1>
  <h2>{{firstname}} {{lastname}}</h2>
  <h1>某值使用的地方多的话,因为computed只计算一次,所以性能比function好很多</h1>
  <h2>{{getFullName()}}</h2>
  <h2>{{getFullName}}</h2>
</div>
<!--viewModel层-->
<script src="../../js/vue.js"></script>
<!--model层-->
<script>
  const app = new Vue({
    el: '#app',
    data: {
      message: 'computed和methods的择优选择',
      firstname: 'kai',
      lastname: 'zhang'
    }, computed: {
      fullName:function () {
        console.log('fullName get()------------只有值改变的时候才会重新调用,因为里边有缓存,强烈推荐')
        return this.lastname + this.firstname
      }
    }, methods: {
      getFullName: function (msg) {
        console.log('getFullName()-------------')
        //声明方法
        return this.lastname + this.firstname
      }
    }, created: function () {
      //生命周期
    }, mounted: function () {
      //生命周期
    }
  })
</script>
</body>
</html>